<div id="ItemSaleDashboard" (click)="clickContainer()">

    <div class="content d-flex flex-column flex-column-fluid">

        <sub-header [title]="'ItemSaleDashboard' | localize" [description]="'ItemSaleDashboard' | localize">
            <div role="actions">
                <div class="row">
                    <div class="col-3">
                        <div class="form-group kt-form__group align-items-center">
                            <label>&nbsp;</label>
                            <div class="input-group" style="font-size: 1.2rem;">
                                <label
                                    style="width: 100%;text-align: right;">{{l('statisticalCategories')}}</label>
                            </div>
                        </div>
                    </div>

                    <div class="col-3" style="margin-top: 1rem;">
                        <div class="form-group kt-form__group align-items-center">
                            <div class="input-group">
                                <select class="form-control" [(ngModel)]="groupByStore" name="groupByStore">
                                    <option value="">{{l('daqu')}}/{{l('province')}}/{{l('store')}}</option>
                                    <option value="AreaName">{{l('daqu')}}</option>
                                    <option value="ProvinceName">{{l('province')}}</option>
                                    <option value="OuterId">{{l('store')}}</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="col-3" style="margin-top: 1rem;">
                        <div class="form-group kt-form__group align-items-center">
                            <div class="input-group">
                                <select class="form-control" [(ngModel)]="groupByProduct" name="groupByProduct">
                                    <option value="">{{l('Brand')}}/{{l('Product')}}{{l('type')}}</option>
                                    <option value="BrandName">{{l('Brand')}}</option>
                                    <option value="SubCategory">{{l('Product')}}{{l('type')}}</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="col-3" style="margin-top: 1rem;">
                        <div class="form-group kt-form__group align-items-center">
                            <div class="input-group">
                                <select class="form-control" [(ngModel)]="groupByMember" name="groupByMember">
                                    <option value="">{{l('Membership')}}/{{l('Activities')}}</option>
                                    <option value="MemberLevel">{{l('Membership')}}</option>
                                    <option value="ActivityTag">{{l('Activities')}}</option>
                                </select>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </sub-header>


        <div [class]="containerClass">
            <div class="card card-custom gutter-b">
                <div class="card-body">
                    <div class="row">
                        <form class="horizontal-form" autocomplete="off">
                            <div class="m-form m-form--label-align-right">
                                <div class="row align-items-center m--margin-bottom-10">
                                    <div class="col-2">
                                        <label
                                            style="margin-bottom: 0rem; position: relative; top: 0.2rem;">{{l('daqu')}}</label>
                                        <app-high-tree #highTree [containerHeight]="'3rem'" [config]="{name:'name'}"
                                            [treeList]="ouTree" (onTreeUpdate)="onTreeUpdate($event)"></app-high-tree>
                                    </div>
                                    <div class="col-2" *ngIf="showTree2">
                                        <label
                                            style="margin-bottom: 0rem; position: relative; top: 0.2rem;">{{l('province')}}</label>
                                        <app-high-tree #highTree2 [containerHeight]="'3rem'" [config]="{name:'name'}"
                                            [treeList]="ouTree2" (onTreeUpdate)="onTreeUpdate2($event)"></app-high-tree>
                                    </div>
                                    <div class="col-2" *ngIf="showTree3">
                                        <label
                                            style="margin-bottom: 0rem; position: relative; top: 0.2rem;">{{l('store')}}</label>
                                        <app-high-tree #highTree3 [containerHeight]="'3rem'" [config]="{name:'name'}"
                                            [treeList]="ouTree3" (onTreeUpdate)="onTreeUpdate3($event)"></app-high-tree>
                                    </div>
                                    <div class="col-2">
                                        <label
                                            style="margin-bottom: 0rem; position: relative; top: 0.2rem;">{{l('Brand')}}</label>
                                        <app-high-tree #highTreeBrand [containerHeight]="'3rem'"
                                            [config]="{name:'name'}" [treeList]="brandList"
                                            (onTreeUpdate)="onTreeUpdateBrand($event)"></app-high-tree>
                                    </div>

                                    <div class="col-2" style="margin-top: 1rem;">
                                        <label>{{l('jancode')}}</label>
                                        <div class="form-group align-items-center">
                                            <div class="input-group">
                                                <input [(ngModel)]="jancode" name="jancode" class="form-control m-input"
                                                    [placeholder]="l('SearchWithThreeDot')" type="text">
                                            </div>
                                        </div>
                                    </div>

                                </div>

                                <div class="row">
                                    <div class="col-2">
                                        <label
                                            style="margin-bottom: 0rem; position: relative; top: 0.2rem;">{{l('firstCategory')}}</label>
                                        <app-high-tree #highTreeFirst [containerHeight]="'3rem'"
                                            [config]="{name:'name'}" [treeList]="firstTree"
                                            (onTreeUpdate)="onTreeUpdateFirst($event)"></app-high-tree>
                                    </div>
                                    <div class="col-2" *ngIf="showTreeSecond">
                                        <label
                                            style="margin-bottom: 0rem; position: relative; top: 0.2rem;">{{l('secondCategory')}}</label>
                                        <app-high-tree #highTreeSecond [containerHeight]="'3rem'"
                                            [config]="{name:'name'}" [treeList]="secondTree"
                                            (onTreeUpdate)="onTreeUpdateSecond($event)"></app-high-tree>
                                    </div>


                                    <div class="col-2">
                                        <label
                                            style="margin-bottom: 0rem; position: relative; top: 0.2rem;">{{l('memberProm')}}</label>
                                        <app-high-tree #highTreeProm [containerHeight]="'3rem'" [config]="{name:'name'}"
                                            [treeList]="promList" (onTreeUpdate)="onTreeUpdateProm($event)">
                                        </app-high-tree>
                                    </div>
                                    <div class="col-2">
                                        <label
                                            style="margin-bottom: 0rem; position: relative; top: 0.2rem;">{{l('Activities')}}{{l('tags')}}</label>
                                        <app-high-tree #highTreeActivity [containerHeight]="'3rem'"
                                            [config]="{name:'name'}" [treeList]="orderActivityTags"
                                            (onTreeUpdate)="onTreeUpdateActivity($event)"></app-high-tree>
                                    </div>


                                    <div class="col-2" style="position:relative;">
                                        <div class="form-group m-form__group align-items-center">
                                            <label>{{l('SalesDate')}}</label>
                                            <date-range-picker needInitDate="true" #clickDateranger style="width: 60%;"
                                                name="clickDateranger" [(startDate)]="realStartTime"
                                                [(endDate)]="realEndTime" [allowFutureDate]="false"
                                                [admitDelete]="true">
                                            </date-range-picker>
                                        </div>
                                    </div>
                                    <div class="col-1">
                                        <label style="display:block;">&nbsp;</label>
                                        <div class="form-group align-items-center">
                                            <div class="input-group">
                                                <button type="button" class="btn btn-primary"
                                                    [buttonBusy]="primengTableHelper.isLoading||!ouTree3.length"
                                                    (click)="getList()">
                                                    <i class="la la-refresh"></i>
                                                    {{l("search")}}
                                                </button>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-1">
                                        <label style="display:block;">&nbsp;</label>
                                        <div class="form-group align-items-center">
                                            <div class="input-group">
                                                <!-- <button type="button" class="btn btn-primary" [buttonBusy]="primengTableHelper.isLoading"
                                                (click)="getList()">
                                                <i class="la la-refresh"></i>
                                                {{l("search")}}
                                            </button> -->
                                                <button type="button" class="btn btn-primary" (click)="export()"
                                                    [buttonBusy]="exportLoading">
                                                    <i class="icon-excel"></i>
                                                    {{l('export')}}</button>
                                            </div>
                                        </div>
                                    </div>
                                </div>




                            </div>
                        </form>
                    </div>


                    <div class="row align-items-center">
                        <!--<Primeng-Datatable-Start>-->
                        <div class="primeng-datatable-container" [busyIf]="primengTableHelper.isLoading">
                            <p-table #dataTable (onLazyLoad)="getList($event)" [value]="primengTableHelper.records"
                                [rows]="primengTableHelper.defaultRecordsCountPerPage" [paginator]="false" [lazy]="true"
                                [resizableColumns]="primengTableHelper.resizableColumns"
                                [responsive]="primengTableHelper.isResponsive" [scrollable]="true" ScrollWidth="100%">
                                <ng-template pTemplate="header">
                                    <tr>
                                        <th style="width:5rem;">{{l('RecordId')}}</th>
                                        <th style="width:15rem;">{{l('daqu')}}</th>
                                        <th style="width:15rem;">{{l('province')}}</th>
                                        <th style="width:15rem;">{{l('city')}}</th>
                                        <th style="width:15rem;">{{l('storeNumber')}}</th>
                                        <th style="width:15rem;">{{l('Stores')}}{{l('name')}}</th>
                                        <th style="width:10rem;">{{l('Stores')}}{{l('type')}}</th>
                                        <th style="width:10rem;">{{l('DeviceType')}}</th>
                                        <th style="width:10rem;">{{l('Stores')}}{{l('status')}}</th>
                                        <th style="width:15rem;">{{l('User')}}{{l('itemId')}}</th>
                                        <th style="width:10rem;">{{l('memberLevel')}}</th>
                                        <th style="width:20rem;">{{l('SalesDate')}}</th>
                                        <th style="width:15rem;">{{l('orderNo')}}</th>
                                        <th style="width:15rem;">{{l('Products')}}{{l('Brand')}}</th>
                                        <th style="width:15rem;">{{l('Products')}}{{l('jancode')}}</th>
                                        <th style="width:25rem;">{{l('Products')}}{{l('name')}}</th>
                                        <th style="width:15rem;">{{l('Products')}}{{l('firstCategory')}}</th>
                                        <th style="width:15rem;">{{l('Products')}}{{l('secondCategory')}}</th>
                                        <th style="width:20rem;">{{l('payTime')}}</th>
                                        <th style="width:10rem;">{{l('orderStatus')}}</th>
                                        <th style="width:15rem;">{{l('Activities')}}{{l('tags')}}</th>
                                        <th style="width:15rem;">{{l('memberProm')}}</th>
                                        <th style="width:20rem;">{{l('suit')}}</th>
                                        <th style="width:15rem;">{{l('salesNumber')}}</th>
                                        <th style="width:15rem;">{{l('TotalSales')}}</th>

                                    </tr>
                                </ng-template>
                                <ng-template pTemplate="body" let-record let-i="rowIndex">
                                    <tr [pSelectableRow]="record" [attr.trid]="record.id">

                                        <td style="width:5rem;">
                                            <span>{{transIndex(i)}}</span>
                                        </td>
                                        <td style="width:15rem;">
                                            <span>{{record.areaName}}</span>
                                        </td>
                                        <td style="width:15rem;">
                                            <span>{{record.provinceName}}</span>
                                        </td>
                                        <td style="width:15rem;">
                                            <span>{{record.cityName}}</span>
                                        </td>
                                        <td style="width:15rem;">
                                            <span>{{record.outerId}}</span>
                                        </td>
                                        <td style="width:15rem;">
                                            <span>{{record.storeName}}</span>
                                        </td>
                                        <td style="width:10rem;">
                                            <span>{{record.storeType}}</span>
                                        </td>
                                        <td style="width:10rem;">
                                            <span>{{record.deviceType}}</span>
                                        </td>
                                        <td style="width:10rem;">
                                            <span>{{record.storeStatus}}</span>
                                        </td>
                                        <td style="width:15rem;">
                                            <span>{{record.memberNo}}</span>
                                        </td>
                                        <td style="width:10rem;">
                                            <span>{{record.memberLevel}}</span>
                                        </td>
                                        <td style="width:20rem;">
                                            <span>{{record.orderDateTime | date : "yyyy/MM/dd HH:mm"}}</span>
                                        </td>
                                        <td style="width:15rem;">
                                            <span>{{record.orderNO}}</span>
                                        </td>
                                        <td style="width:15rem;">
                                            <span>{{record.brandName}}</span>
                                        </td>
                                        <td style="width:15rem;">
                                            <span>{{record.skuId}}</span>
                                        </td>
                                        <td style="width:25rem;">
                                            <span>{{record.title}}</span>
                                        </td>
                                        <td style="width:15rem;">
                                            <span>{{record.category}}</span>
                                        </td>
                                        <td style="width:15rem;">
                                            <span>{{record.subCategory}}</span>
                                        </td>
                                        <td style="width:20rem;">
                                            <span>{{record.payTime| date : "yyyy/MM/dd HH:mm"}}</span>
                                        </td>
                                        <td style="width:10rem;">
                                            <span>{{record.orderStatus}}</span>
                                        </td>
                                        <td style="width:15rem;">
                                            <span>{{record.activityTag}}</span>
                                        </td>
                                        <td style="width:15rem;">
                                            <span>{{record.discount}}</span>
                                        </td>
                                        <td style="width:20rem;">
                                            <span>{{record.isSuite}}</span>
                                        </td>
                                        <td style="width:15rem;">
                                            <span>{{record.number}}</span>
                                        </td>
                                        <td style="width:15rem;">
                                            <span>{{record.payment}}</span>
                                        </td>
                                    </tr>
                                </ng-template>
                                <ng-template pTemplate="emptymessage" let-records>
                                    <tr *ngIf="primengTableHelper.records">
                                        <td colspan="15">
                                            <img class="emptymessage"
                                                src="/assets/common/images/placeholder/deviceHolder.png" />
                                        </td>
                                    </tr>
                                </ng-template>
                            </p-table>
                            <div class="primeng-paging-container">
                                <p-paginator [rows]="primengTableHelper.defaultRecordsCountPerPage" #paginator
                                    (onPageChange)="getList($event)"
                                    [totalRecords]="primengTableHelper.totalRecordsCount"
                                    [rowsPerPageOptions]="primengTableHelper.predefinedRecordsCountPerPage">
                                </p-paginator>
                                <span class="total-records-count">
                                    {{l('TotalRecordsCount', primengTableHelper.totalRecordsCount)}}
                                </span>
                            </div>
                        </div>
                        <!--<Primeng-Datatable-End>-->
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>